package com.ruoyi.dataBase.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.dev33.satoken.annotation.SaMode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dataBase.domain.vo.IndustrialReportObjVo;
import com.ruoyi.dataBase.domain.bo.IndustrialReportObjBo;
import com.ruoyi.dataBase.service.IIndustrialReportObjService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 填报对象
 *
 * @author yangzhen
 * @date 2025-11-07
 */
@Tag(name = "填报对象", description = "职能部门相关接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dataBase/reportObj")
public class IndustrialReportObjController extends BaseController {

    private final IIndustrialReportObjService iIndustrialReportObjService;

    /**
     * 查询填报对象列表
     */
    @Operation(summary = "查询填报对象列表", description = "用于查询填报对象列表")
    @SaCheckPermission("dataBase:reportObj:list")
    @GetMapping("/list")
    public TableDataInfo<IndustrialReportObjVo> list(IndustrialReportObjBo bo, PageQuery pageQuery) {
        return iIndustrialReportObjService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出填报对象列表
     */
    @Operation(summary = "导出填报对象列表", description = "用于导出填报对象列表")
    @SaCheckPermission("dataBase:reportObj:export")
    @Log(title = "填报对象", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IndustrialReportObjBo bo, HttpServletResponse response) {
        List<IndustrialReportObjVo> list = iIndustrialReportObjService.queryList(bo);
        ExcelUtil.exportExcel(list, "填报对象", IndustrialReportObjVo.class, response);
    }

    /**
     * 获取填报对象详细信息
     *
     * @param id 主键
     */
    @Operation(summary = "获取填报对象详细信息", description = "用于获取填报对象详细信息")
    @SaCheckPermission("dataBase:reportObj:query")
    @GetMapping("/{id}")
    public R<IndustrialReportObjVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iIndustrialReportObjService.queryById(id));
    }

    /**
     * 新增填报对象
     */
    @Operation(summary = "新增填报对象", description = "用于新增填报对象")
    @SaCheckPermission("dataBase:reportObj:add")
    @Log(title = "填报对象", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IndustrialReportObjBo bo) {
        return toAjax(iIndustrialReportObjService.insertByBo(bo));
    }

    /**
     * 修改填报对象
     */
    @Operation(summary = "修改填报对象", description = "用于修改填报对象")
    @SaCheckPermission(value = {"dataBase:reportObj:edit", "dataBase:reportObj:review"}, mode = SaMode.OR)
    @Log(title = "填报对象", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IndustrialReportObjBo bo) {
        return toAjax(iIndustrialReportObjService.updateByBo(bo));
    }

    /**
     * 删除填报对象
     *
     * @param ids 主键串
     */
    @Operation(summary = "删除填报对象", description = "用于删除填报对象")
    @SaCheckPermission("dataBase:reportObj:remove")
    @Log(title = "填报对象", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iIndustrialReportObjService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
